<?php
namespace other;

/*header("Content-type: text/html; charset=utf-8");

短信后台
链接：http://139.196.215.111:8081
账号：chengjiao
密码：P6VLZIsXw>

接口文档：https://www.showdoc.com.cn/872195016401251/4702299216933453
文档密码：123123
提交短信接口地址：http://139.196.215.111:8087/json/submit
企业编号(enterprise_no)：10011
账号（account）：chengjiao
秘钥(http_sign_Key)：D5F468081EB93D9C0AB1837FD59F9CE4

$result=MessageSend::send($account,$password,$mobiles,$extno,$content,$sendtime);
$xml = simplexml_load_string($result);

echo "返回信息提示:".$xml->message;
echo "返回状态为:".$xml->returnstatus;
echo "返回信息:".$xml->message;
echo "返回余额:".$xml->remainpoint;
echo "返回本次任务ID:".$xml->taskID;
echo "返回成功短信数:".$xml->successCounts;*/

//aspx接口调用
class SmsWYSend
{
    const url ="http://139.196.215.111:8087/json/submit";
    const enterprise_no ="10011";
    const account ="chengjiao";
    const http_sign_Key ="D5F468081EB93D9C0AB1837FD59F9CE4";

    // 正常通知短信
    static function send($mobiles,$content)
    {
        // 排除YCC短信
//        $not_send_mobile = \db('admin')->where('id', 6)->value('tel');
//        if (!empty($not_send_mobile) && $not_send_mobile == $mobiles) {
//            // 短信发送时间限制
//            $time_range = \db('system_config')->where('_key','send_sms_time')->where('status', 1)->value('extra');
//            if (!empty($time_range)) {
//                $time_array = explode(" - ", $time_range);
//
//                if (count($time_array) >= 2) {
//                    list($start, $end) = $time_array;
//
//                    $start = date("His", strtotime($start)); // 开始时间
//                    $end = date("His", strtotime($end)); // 结束时间
//                    $time = date("His", time()); // 当前时间
//                    // 开始时间结束时间相等则 不做限制
//
//                    // 开始时间大于结束时间,则当前时间大于开始时间即可
//                    if ($start > $end && $time < $start && $time > $end) {
//                        return false;
//                    }
//
//                    // 开始时间小于结束时间, 则当前时间必须在时间段内
//                    if ($start < $end && ($time < $start || $time > $end) ) {
//                        return false;
//                    }
//                }
//            }
//        }

        //MD5(enterprise_no+account+timestamp+http_sign_Key)
        $time=date('YmdHis');
        $sign=strtoupper(md5(self::enterprise_no.self::account.$time.self::http_sign_Key));
        $body=array(
            'enterprise_no'=>self::enterprise_no,
            'account'=>self::account,
            'phones'=>$mobiles,
            'content'=>$content,
            'timestamp'=>$time,
            'sign'=>$sign
        );

        $ch=curl_init();
        curl_setopt($ch, CURLOPT_URL, self::url);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
        curl_setopt($ch, CURLOPT_HTTPHEADER,array(
            'Content-Type: application/json; charset=utf-8'
        ));
        $result = curl_exec($ch);
        curl_close($ch);
        return $result;
    }

    // 发送验证码
    static function sendCode($mobiles,$content)
    {
        $time=date('YmdHis');
        $sign=strtoupper(md5(self::enterprise_no.self::account.$time.self::http_sign_Key));
        $body=array(
            'enterprise_no'=>self::enterprise_no,
            'account'=>self::account,
            'phones'=>$mobiles,
            'content'=>$content,
            'timestamp'=>$time,
            'sign'=>$sign
        );

        $ch=curl_init();
        curl_setopt($ch, CURLOPT_URL, self::url);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body));
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
        curl_setopt($ch, CURLOPT_HTTPHEADER,array(
            'Content-Type: application/json; charset=utf-8'
        ));
        $result = curl_exec($ch);
        curl_close($ch);
        return $result;
    }
}
?>